<template>
  <div id="app">
    <div class="nav-kong" v-if="path != 'login' && path != 'SearchPage' && path != 'loginLoad'"></div>
    <Nav v-if="path != 'login' && path != 'SearchPage' && path != 'loginLoad'"></Nav>
    <router-view />
  </div>
</template>

<script>
import storage from "@/plugins/storage";
import { getBaseSite } from "@/api/common.js";
import Nav from "@/components/home_nav/nav.vue";
export default {
  data() {
    return {
      path: "login",
    };
  },
  name: "App",
  mounted() {
    this.init();
    this.path = this.$route.name; //处理刷新商城页面导航栏丢失
  },
  // 数据监听：监听组件实例身上的属性的属性值变化
  watch: {
    $route(val) {
      this.path = val.name;
    },
  },
  //处理导航栏menu的选中
  updated() {
    this.path = this.$route.name;
    document.documentElement.scrollTop = 0;
    window.pageYOffset = 0;
    document.body.scrollTop = 0;
  },
  components: {
    Nav,
  },
  methods: {
    init() {
      if (
        !storage.getItem("siteName") ||
        !storage.getItem("logoImg") ||
        !storage.getItem("sitelogo_expiration_time")
      ) {
        this.getSite();
      } else {
        // 如果缓存过期，则获取最新的信息
        if (new Date() > storage.getItem("sitelogo_expiration_time")) {
          this.getSite();
          return;
        } else {
          window.document.title = "运动健康综合用户端";
          //动态获取icon
          //   let link =
          //     document.querySelector("link[rel*='icon']") ||
          //     document.createElement("link");
          //   link.type = "image/x-icon";
          //   link.href = storage.getItem("logoImg");
          //   link.rel = "shortcut icon";
          //   document.getElementsByTagName("head")[0].appendChild(link);
        }
      }
    },
    getSite() {
      //获取基本站点信息
      getBaseSite().then((res) => {
        if (res.success && res.result.settingValue) {
          let data = JSON.parse(res.result.settingValue);
          // 过期时间
          var expirationTime = new Date().setHours(new Date().getHours() + 1);
          // 存放过期时间
          storage.setItem("sitelogo_expiration_time", expirationTime);
          // 存放信息
          storage.setItem("siteName", data.siteName);
          storage.setItem("logoImg", data.buyerSideLogo);

          window.document.title = data.siteName;
          //动态获取icon
          //   let link =
          //     document.querySelector("link[rel*='icon']") ||
          //     document.createElement("link");
          //   link.type = "image/x-icon";
          //   link.href = data.buyerSideLogo;
          //   link.rel = "shortcut icon";
          //   document.getElementsByTagName("head")[0].appendChild(link);
        }
      });
    },
  },
};
</script>
<style lang="scss">
* {
  box-sizing: border-box;
  padding: 0;
  margin: 0;
  &::-webkit-scrollbar {
    width: 0.375rem;
    height: 0.375rem;
  }
  &::-webkit-scrollbar-thumb {
    border-radius: 5px;
    -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
    background-color: #99a9bf;
  }
  &::-webkit-scrollbar-track {
    -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
    border-radius: 5px;
    background-color: #d3dce6;
  }
}
.nav-kong {
  // width: 100vw;
  height: calc(80 / 1920 * 100vw);
}
#app {
  @include background_color($light_background_color);
  // overflow-y: hidden;
}
</style>
